home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
DELPHI32
/
GRIDS
/
SPREAD32
/
SPREAD32.ZIP
/
unit1.pas
< prev
Wrap
Pascal/Delphi Source File
|
1996-08-15
|
10KB
|
304 lines
unit Unit1;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Grids, spread, ExtCtrls, Menus, StdCtrls, Spin;
type
TForm1 = class(TForm)
Spread1: TSpread;
MainMenu1: TMainMenu;
File1: TMenuItem;
Exit1: TMenuItem;
Panel1: TPanel;
Label1: TLabel;
ComboBox1: TComboBox;
Label2: TLabel;
ColorDialog1: TColorDialog;
FontDialog1: TFontDialog;
OpenDialog1: TOpenDialog;
Button1: TButton;
Bevel1: TBevel;
Label3: TLabel;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
Label4: TLabel;
SpinEdit1: TSpinEdit;
Label5: TLabel;
ComboBox2: TComboBox;
Label6: TLabel;
ComboBox3: TComboBox;
Button2: TButton;
procedure Exit1Click(Sender: TObject);
procedure Spread1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SetColumnHeaders;
procedure SetRowHeaders;
procedure Spread1CellTypeViol(icol, irow: Longint; Celltype,
CellEntrytype: Tctype; cellstring: String;
var NewCellstring: OpenString; var changecelltype: Boolean);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Exit1Click(Sender: TObject);
begin
Application.Terminate;
end;
procedure TForm1.Spread1Click(Sender: TObject);
var
T : Tctype;
begin
label2.caption := 'Col = '+inttostr(spread1.col)+ ' Row = '+inttostr(spread1.row);
T := spread1.Getcelltype(spread1.col,spread1.row);
case T of
cttext : label2.caption := label2.caption + ' cttext';
ctformula : label2.caption := label2.caption + ' ctformula';
ctdate : label2.caption := label2.caption + ' ctdate';
cttime : label2.caption := label2.caption + ' cttime';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Bmp : TBitmap;
Br : TBrush;
F : TFont;
Al : TAlignment;
Fmt : TFloatFormat;
begin
case combobox1.itemindex of
0 :
begin
spread1.addcol;
setcolumnheaders;
setrowheaders;
end;
1 : spread1.addrow;
2 : spread1.clearbitmap(spread1.col,spread1.row);
3 :
begin
spread1.deletecol(spread1.col);
setcolumnheaders;
setrowheaders;
end;
4 : spread1.deleterow(spread1.row);
5 : spread1.hidecol(spread1.col);
6 : spread1.hiderow(spread1.row);
7 :
begin
spread1.insertcol(spread1.col);
setcolumnheaders;
setrowheaders;
end;
8 :begin
spread1.insertrow(spread1.row);
setrowheaders;
end;
9 : spread1.lockcell(spread1.col,spread1.row);
10: spread1.lockcol(spread1.col);
11: spread1.lockrow(spread1.row);
12: spread1.makebutton(spread1.col,spread1.row,'Button','');
13: spread1.makecheckbox(spread1.col,spread1.row,'Checkbox',true,'');
14:
begin
spread1.makecombobox(spread1.col,spread1.row,csdropdown,'');
spread1.addtocombo(spread1.col,spread1.row,'One');
spread1.addtocombo(spread1.col,spread1.row,'Two');
spread1.addtocombo(spread1.col,spread1.row,'Three');
spread1.addtocombo(spread1.col,spread1.row,'Four');
spread1.addtocombo(spread1.col,spread1.row,'Five');
spread1.addtocombo(spread1.col,spread1.row,'Six');
spread1.addtocombo(spread1.col,spread1.row,'Seven');
spread1.addtocombo(spread1.col,spread1.row,'Eight');
spread1.addtocombo(spread1.col,spread1.row,'Nine');
spread1.addtocombo(spread1.col,spread1.row,'Ten');
end;
15: spread1.makenewsheet;
16: spread1.makespinedit(spread1.col,spread1.row,0,'');
17:begin
if opendialog1.execute then
begin
Bmp := TBitmap.create;
Bmp.Loadfromfile(opendialog1.filename);
spread1.putbitmap(spread1.col,spread1.row,Bmp);
Bmp.free;
end;
end;
18:begin
if colordialog1.execute then
begin
Br := TBrush.Create;
Br.color := colordialog1.color;
spread1.setcellbrush(spread1.col,spread1.row,Br);
Br.Free;
end;
end;
19:begin
if colordialog1.execute then
begin
Br := TBrush.Create;
Br.color := colordialog1.color;
spread1.setcolbrush(spread1.col,Br);
Br.Free;
end;
end;
20:begin
if colordialog1.execute then
begin
Br := TBrush.Create;
Br.color := colordialog1.color;
spread1.setrowbrush(spread1.row,Br);
Br.Free;
end;
end;
21:begin
if fontdialog1.execute then
begin
F := TFont.create;
F.Assign(fontdialog1.font);
spread1.setcellfont(spread1.col,spread1.row,F);
F.Free;
end;
end;
22:begin
if fontdialog1.execute then
begin
F := TFont.create;
F.Assign(fontdialog1.font);
spread1.setcolfont(spread1.col,F);
F.Free;
end;
end;
23:begin
if fontdialog1.execute then
begin
F := TFont.create;
F.Assign(fontdialog1.font);
spread1.setrowfont(spread1.row,F);
F.Free;
end;
end;
24,25,26:begin
if radiobutton1.checked then
Al := taLeftJustify
else if radiobutton2.checked then
Al := taRightJustify
else
Al := taCenter;
if combobox1.itemindex = 24 then
spread1.setcellalignment(spread1.col,spread1.row,Al)
else if combobox1.itemindex = 25 then
spread1.setcolalignment(spread1.col,Al)
else
spread1.setrowalignment(spread1.row,Al);
end;
27,28,29: (* set cell col or row format *)
begin
case combobox2.itemindex of
0 : Fmt := ffCurrency;
1 : Fmt := ffNumber;
2 : Fmt := ffFixed;
3 : Fmt := ffGeneral;
4 : Fmt := ffExponent;
end;
if combobox1.itemindex = 27 then
spread1.setcellformat(spread1.col,spread1.row,Fmt,spinedit1.value)
else if combobox1.itemindex = 28 then
spread1.setcolformat(spread1.col,Fmt,spinedit1.value)
else
spread1.setrowformat(spread1.row,Fmt,spinedit1.value);
end;
30 : (* set cell type*)
begin
case combobox3.itemindex of
0 : spread1.setcelltype(spread1.col,spread1.row,cttext);
1 : spread1.setcelltype(spread1.col,spread1.row,ctformula);
2 : spread1.setcelltype(spread1.col,spread1.row,ctdate);
3 : spread1.setcelltype(spread1.col,spread1.row,cttime);
end;
end;
31 : spread1.unlockallcells;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SetColumnHeaders;
setrowheaders;
end;
procedure TForm1.SetColumnHeaders;
var
i : integer;
begin
for i := 0 to spread1.colcount - 1 do
spread1.cells[i,0] :=inttostr(i);
end;
procedure TForm1.SetRowHeaders;
var
i : integer;
begin
for i := 0 to spread1.rowcount - 1 do
spread1.cells[0,i] :=inttostr(i);
end;
procedure TForm1.Spread1CellTypeViol(icol, irow: Longint; Celltype,
CellEntrytype: Tctype; cellstring: String; var NewCellstring: OpenString;
var changecelltype: Boolean);
begin
changecelltype := true;
(* setting changecelltype to true prevents
TSpread from generating an error message
when the user types text in a cell which cannot
be evaluated as a formula. If changecelltype
is not set to true then an error message and
the error event handler is fired.
Note that the celltype is ctformula but
after this event TSpread changes the type
to cttext since the entry can't be evaluated
as a formula.
*)
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i : integer;
begin
for i := 1 to 10 do
begin
spread1.setcelltype(1,i,ctformula);
spread1.setformula(1,i,inttostr(i));
end;
spread1.setcolalignment(1,taRightJustify);
spread1.setcelltype(1,11,ctformula);
spread1.setformula(1,11,'=a1+a2+a3+a4+a5+a6+a7+a8+a9+a10');
for i := 1 to 10 do
begin
spread1.setcelltype(2,i,ctformula);
spread1.setformula(2,i,'=a'+inttostr(i));
end;
spread1.setcolalignment(2,taRightJustify);
spread1.setcelltype(2,11,ctformula);
spread1.setformula(2,11,'=b1+b2+b3+b4+b5+b6+b7+b8+b9+b10');
end;
end.